﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VPN.Manage
{
    [Serializable]
    public class POSearchArg
    {
        public string PONumber;
        public string UserName;
        public Guid AccountID;
        public POStatus POStatus;
        public DateTime? CreateDateStart;
        public DateTime? CreateDateEnd;
        public DateTime? PayDateStart;
        public DateTime? PayDateEnd;

        public POSearchArg(string q)
        {
            string[] searchArg = !string.IsNullOrEmpty(q) ? q.Split(",".ToCharArray()) : new string[8];

            PONumber = searchArg[0];  //po number
            UserName = searchArg[1];   //user name
            POStatus = string.IsNullOrEmpty(searchArg[2]) ? POStatus.All : (POStatus)Convert.ToInt32(searchArg[2]); //po status
            AccountID = string.IsNullOrEmpty(searchArg[3]) ? Guid.Empty : new Guid(searchArg[3]); //account id
            CreateDateStart = string.IsNullOrEmpty(searchArg[4]) ? (DateTime?)null : DateTime.Parse(searchArg[4]);    //po create date start
            CreateDateEnd = string.IsNullOrEmpty(searchArg[5]) ? (DateTime?)null : DateTime.Parse(searchArg[5]);   //po create date end
            PayDateStart = string.IsNullOrEmpty(searchArg[6]) ? (DateTime?)null : DateTime.Parse(searchArg[6]);   //po pay date start
            PayDateEnd = string.IsNullOrEmpty(searchArg[7]) ? (DateTime?)null : DateTime.Parse(searchArg[7]);   //po pay date end
        }

        public POSearchArg()
        {
        }

        public override string ToString()
        {
            string[] s = new string[8];
            s[0] = PONumber;
            s[1] = UserName;
            s[2] = ((int)POStatus).ToString();
            s[3] = AccountID == Guid.Empty ? string.Empty : AccountID.ToString();
            s[4] = CreateDateStart.HasValue ? CreateDateStart.Value.ToString("yyyy-MM-dd") : string.Empty;
            s[5] = CreateDateEnd.HasValue ? CreateDateEnd.Value.ToString("yyyy-MM-dd") : string.Empty;
            s[6] = PayDateStart.HasValue ? PayDateStart.Value.ToString("yyyy-MM-dd") : string.Empty;
            s[7] = PayDateEnd.HasValue ? PayDateEnd.Value.ToString("yyyy-MM-dd") : string.Empty;
            return string.Join(",", s);
        }


    }
}
